﻿document.write('<script src="script/jquery.js"></script>');
var is_collapsed = false;
function ToggleCollapse()
{
    if (is_collapsed) { 
        document.getElementById("nav").style.display = '';
        document.getElementById("collapse").style.display = "";
        document.getElementById("expand").style.display = 'none';
        is_collapsed = false;
    } else {
        document.getElementById("nav").style.display = 'none';
        document.getElementById("collapse").style.display = "none";
        document.getElementById("expand").style.display = '';
        is_collapsed = true;
    }
}

var channel_collapsed = false;
function channelCollapse()
{
    if (channel_collapsed) { 
        document.getElementById("channel-container").style.display = '';
        document.getElementById("channel-down").style.display = "";
        document.getElementById("channel-right").style.display = 'none';
        channel_collapsed = false;
    } else {
        document.getElementById("channel-container").style.display = 'none';
        document.getElementById("channel-down").style.display = "none";
        document.getElementById("channel-right").style.display = '';
        channel_collapsed = true;
    }
}
var provider_collapsed = false;
function providerCollapse()

{

    if (provider_collapsed) { 

        document.getElementById("provider-container").style.display = '';

        document.getElementById("provider-down").style.display = "";

        document.getElementById("provider-right").style.display = 'none';

        provider_collapsed = false;

    } else {

        document.getElementById("provider-container").style.display = 'none';

        document.getElementById("provider-down").style.display = "none";

        document.getElementById("provider-right").style.display = '';

        provider_collapsed = true;

    }

}



var publisher_collapsed = false;

function publisherCollapse()

{

    if (publisher_collapsed) { 

        document.getElementById("publisher-container").style.display = '';

        document.getElementById("publisher-down").style.display = "";

        document.getElementById("publisher-right").style.display = 'none';

        provider_collapsed = false;

    } else {

        document.getElementById("publisher-container").style.display = 'none';

        document.getElementById("publisher-down").style.display = "none";

        document.getElementById("publisher-right").style.display = '';

        provider_collapsed = true;

    }

}



var reader_collapsed = false;

function readerCollapse()

{

    if (reader_collapsed) { 

        document.getElementById("reader-container").style.display = '';

        document.getElementById("reader-down").style.display = "";

        document.getElementById("reader-right").style.display = 'none';

        reader_collapsed = false;

    } else {

        document.getElementById("reader-container").style.display = 'none';

        document.getElementById("reader-down").style.display = "none";

        document.getElementById("reader-right").style.display = '';

        reader_collapsed = true;

    }

}



function showAddChannel()
{
	document.getElementById("main-right-box").src = "admin_add_channel.php";	
}



function showAddProvider()
{
	document.getElementById("main-right-box").src = "admin_add_provider.php";
}
function showAddPublisher()

{

	document.getElementById("main-right-box").src = "admin_add_publisher.php";	

}



function showAddReader()

{

	document.getElementById("main-right-box").src = "admin_add_reader.php";	

}



function sendTo(url,param)

{ 

	var req = false; 

	

	document.getElementById("status").style.display = 'block';

	document.getElementById("status").innerHTML=".......";

	

	if (window.XMLHttpRequest) { // Mozilla, Safari,...

         req = new XMLHttpRequest();

         if (req.overrideMimeType) {

         	// set type accordingly to anticipated content type

            //req.overrideMimeType('text/xml');

            req.overrideMimeType('text/html');

         }

      } else if (window.ActiveXObject) { // IE

         try {

            req = new ActiveXObject("Msxml2.XMLHTTP");

         } catch (e) {

            try {

               req = new ActiveXObject("Microsoft.XMLHTTP");

            } catch (e) {}

         }

      }

      if (!req) {

         alert('Cannot create XMLHTTP instance');

         return false;

      }



	req.onreadystatechange = function()

	{ 

		document.getElementById("status").innerHTML="Wait server...";

		if(req.readyState == 4)

		{

			if(req.status == 200)

			{

				document.getElementById("status").innerHTML=req.responseText;	

			}	

			else	

			{

				document.getElementById("status").innerHTML="Error: returned status code " + req.status + " " + req.statusText;

			}	

		} 

	}; 

	req.open("POST", url, true); 

	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 

	req.setRequestHeader("Content-length", param.length);

	req.setRequestHeader("Connection", "close");

	req.send(param);

} 



function searchChannel()
{
	var t = document.getElementById("channel-title").value;
	var l = document.getElementById("channel-link").value;
	var r = document.getElementById("channel-rank").value;
	document.getElementById("main-right-box").src = "search_channel.php?title="+t+"&link="+l+"&rank="+r;
}



function searchProvider()
{
	var u = document.getElementById("provider-username").value;
	var f = document.getElementById("provider-fname").value;
	var l = document.getElementById("provider-lname").value;
	var c = document.getElementById("provider-company").value;
	document.getElementById("main-right-box").src = "search_provider.php?username="+u+"&fname="+f+"&lname="+l+"&company="+c;
}



function searchPublisher()
{
	var u = document.getElementById("publisher-username").value;
	var f = document.getElementById("publisher-fname").value;
	var l = document.getElementById("publisher-lname").value;
	var c = document.getElementById("publisher-company").value;
	document.getElementById("main-right-box").src = "search_publisher.php?username="+u+"&fname="+f+"&lname="+l+"&company="+c;
}



function searchReader()
{
	var u = document.getElementById("reader-username").value;
	var f = document.getElementById("reader-fname").value;
	var l = document.getElementById("reader-lname").value;
	var c = document.getElementById("reader-company").value;
	document.getElementById("main-right-box").src = "search_reader.php?username="+u+"&fname="+f+"&lname="+l+"&company="+c;
}



function viewFeed(id,title,page,perpage){

		document.getElementById("main-right-box").src = "reader_read_items.php?id="+id+"&title="+title+"&page="+page+"&perpage="+perpage;

}

function nextpage (channelid, key,page,perpage){

	alert(page);

	searchItem(channelid, key,parseInt(page)+1,perpage);

}

function prevpage (channelid, key,page,perpage){

	searchItem(channelid, key,parseInt(page)-1,perpage);

}

function addReader(){

	var param = ""

	param += "username="+/*escape*/(document.form.username.value);

	param += "&password="+/*escape*/(document.form.password.value);

	param += "&fname="+/*escape*/(document.form.fname.value);

	param += "&lname="+/*escape*/(document.form.lname.value);

	param += "&company="+/*escape*/(document.form.company.value);

	param += "&rank="+/*escape*/(document.form.rank.value);

	sendTo("admin_operation.php?action=add_reader",param);

}



function addProvider(){

	var param = ""

	param += "username="+/*escape*/(document.form.username.value);

	param += "&password="+/*escape*/(document.form.password.value);

	param += "&fname="+/*escape*/(document.form.fname.value);

	param += "&lname="+/*escape*/(document.form.lname.value);

	param += "&company="+/*escape*/(document.form.company.value);

	param += "&chIdArray="+/*escape*/(serialize(document.form.elements['chIdArray[]']));

	sendTo("admin_operation.php?action=add_provider",param);

}



function addPublisher(){

	var param = ""

	param += "username="+/*escape*/(document.form.username.value);

	param += "&password="+/*escape*/(document.form.password.value);

	param += "&fname="+/*escape*/(document.form.fname.value);

	param += "&lname="+/*escape*/(document.form.lname.value);

	param += "&company="+/*escape*/(document.form.company.value);

	param += "&chIdArray="+/*escape*/(serialize(document.form.elements['chIdArray[]']));

	sendTo("admin_operation.php?action=add_publisher",param);

}



function serialize(checkbox){

	var a = new Array();

	var j = 0;

	for(var i=0; i < checkbox.length; i++){

		if(checkbox[i].checked){

			a[j] = checkbox[i].value;

			j++;

		}

	}

	return a.toString();

}



function editReader(){

	var param = ""

	param += "username="+/*escape*/(document.form.username.value);

	if(document.form.password.value != "")

		param += "&password="+/*escape*/(document.form.password.value);

	param += "&fname="+/*escape*/(document.form.fname.value);

	param += "&lname="+/*escape*/(document.form.lname.value);

	param += "&company="+/*escape*/(document.form.company.value);

	param += "&rank="+/*escape*/(document.form.rank.value);

	sendTo("admin_operation.php?action=edit_reader",param);

}


function editProvider(){

	var param = ""

	param += "username="+/*escape*/(document.form.username.value);

	param += "&password="+/*escape*/(document.form.password.value);

	param += "&fname="+/*escape*/(document.form.fname.value);

	param += "&lname="+/*escape*/(document.form.lname.value);

	param += "&company="+/*escape*/(document.form.company.value);

	param += "&chIdArray="+/*escape*/(serialize(document.form.elements['chIdArray[]']));

	sendTo("admin_operation.php?action=edit_provider",param);

}



function editPublisher(){

	var param = ""

	param += "username="+/*escape*/(document.form.username.value);

	param += "&password="+/*escape*/(document.form.password.value);

	param += "&fname="+/*escape*/(document.form.fname.value);

	param += "&lname="+/*escape*/(document.form.lname.value);

	param += "&company="+/*escape*/(document.form.company.value);

	param += "&chIdArray="+/*escape*/(serialize(document.form.elements['chIdArray[]']));

	sendTo("admin_operation.php?action=edit_publisher",param);

}



function editItem(){

	var param = ""

	param += "title="+/*escape*/(document.form.title.value);

	param += "&pubdate="+/*escape*/(document.form.pubdate.value);

	param += "&guid="+/*escape*/(document.form.guid.value);

	//param += "&description="+escape(tinyMCE.getContent());

	param += "&description="+escape(tinyMCE.activeEditor.getContent());

	param += "&itemid="+/*escape*/(document.form.itemid.value);

	sendTo("provider_operation.php?action=edit_item",param);

}


function urlencode(input){

	var output = "";

	for(i=0;i<input.length;i++){

		if(input[i]>='ก'){

			output += '%'+(input[i].charCodeAt(0)-'ก'.charCodeAt(0)+161).toString(16);

		}else{

			output += input[i];

		}

	}

	return output;

}

function add_another_file(){

	

}